Skip to content

feat: Add desktop HTML page annotations - #202

Open
LIUXIN557 wants to merge 37 commits into
masterfrom
codex/html-page-annotations
Open

LIUXIN557 wants to merge 37 commits into
masterfrom
codex/html-page-annotations

Conversation

@LIUXIN557

@LIUXIN557 LIUXIN557 commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implement approved Windows/macOS desktop HTML page annotations through OpenSpec change add-html-page-annotations.

Product/test integration at 39cd01db: trusted popup and retained pins/previews, multiple targets/one region, receipt-only batch reconciliation with leased first admission, navigation/default-stay protection, exact-target invalidation, UI-owned request deadlines/cancellation, and native full-page scrollbar-layout preservation. Frozen capture validation survives ordinary reads/next-draft commands; cancellation/deadline actively retires owned capture styles without awaiting a lost screenshot callback. Higher-seam tests now exercise the actual lease-release lifecycle. The Linux HTTP assertion classifies typed internal request-context records separately from real user admissions.

Final evidence-only documentation commit: 51358370; product/test sources are identical to verified 39cd01db.

Closes #193
Closes #194
Closes #195
Closes #196
Closes #197
Closes #198
Closes #199
Closes #200
Closes #201

Validation

  • At unchanged 39cd01db, full pnpm test, production build and regex compatibility checks passed. Directly rebuilt TEMP native driver plus the dedicated Chromium interaction/controller/native-session/HTTP/receiver-queue integration passed; exact-DOM/shadow lifecycle smoke passed.
  • Standards and Spec reviews re-pinned to 0155a863...51358370 report no open code findings; prior retry/text, explicit-read race, active capture cleanup and integration lease-adapter findings are closed within documented test boundaries. Reviewers independently rebuilt the 63-test native composition suite and exercised the combined integration fix. Platform acceptance and the unresolved cascade contract remain separate.
  • All four strict gates (dependency layers, source size, ownership/final and documentation paths), OpenSpec strict and diff checks passed at 51358370, without baseline increases. Documentation-path validation initially identified one quoted prose token mistaken for a tracked path; the final documentation-only commit corrects the wording. No baseline waiver was introduced.
  • At unchanged, clean 39cd01db, Windows desktop/unit/smoke rebuilding passed with valid native dependency records; 107 focused native tests and 107 CTest cases passed, including freshly linked receipt HTTP and payload classification regressions. Actual visible integrated WebView2 smoke passed, checking below-viewport green pixels and unchanged root layout, viewport, scroll and author styles, plus stale-document/resource rejection and retry. Earlier reliable 4b0c00c4 rebuilding also passed. Its hidden-launch attempt failed the active-visible harness check; the visible rerun passed. Neither smoke replaces the complete annotation manual workflow.
  • An old generated MSVC showIncludes prefix was mojibake; Ninja recorded zero project-header dependencies and reused stale ABI objects. Only ignored local compiler-cache files were corrected. All 1674 old zero-dependency objects were invalidated and reliably recompiled; routes_ws now records 747 valid dependencies. Earlier incremental native passes are not proof that all changed headers were compiled.
  • Supplemental independent WebView2 smoke passed normal/stable/both-edges/thin/horizontal variants: 845x2400 PNG includes bottom green with viewport, scroll, root layout, original inline styles and author stylesheet membership preserved. Unsupported author-important cascade fails explicitly with preserved state. All 104 refactoring/tooling tests passed at 4b0c00c4; no tooling implementation changes were added afterward.
  • The previous native unit binary completed 7119 tests: 7088 passed, 20 skipped, 11 failed, and 1 disabled. Failures span pointer hit-testing, TCP reachability, hook timing, skill seed, PowerShell encoding and turn-interrupt tests. Baseline reproduction has not been established; no full-suite success is claimed.
  • Linux CI run 44369114282 passed 7057 of 7058 executed tests, with one annotation receipt-test failure: typed internal execution context was counted as another user admission. The integrated test-only fix preserves exactly-one/body/metadata/receipt/conflict assertions, seeds context deterministically, and uses established serialization/classification. Independent replay, duplicate/missing-metadata mutation checks and receiver tests passed; a fresh Linux CI pass is not yet claimed. Other jobs in that run passed.
  • Fresh PR CI at 51358370 is queued: run 44381864976. A duplicate manual dispatch was cancelled after the automatic PR run appeared; no fresh remote result is claimed.
  • A worker's earlier concurrent full frontend run failed readiness while standalone and coordinator fixed-HEAD runs passed. This historical failure is retained, not attributed to a proven baseline or waived by weakening assertions.

Remaining Work / Known Findings

  • Obtain a passing fresh Linux CI run after the receipt-test classification correction. No viewport fallback or relaxed capture validation.
  • Clarify explicit failure semantics when existing important declarations prevent an independent preview stylesheet from taking effect; do not modify original inline declarations or silently change supported platforms.
  • Real Windows complete desktop workflow and macOS build/native/manual acceptance have not passed. Keep this PR draft until both required platform workflows and remaining gates pass.

OpenSpec tasks 5.1 (Windows native full-page capture), 8.1 (automated integration) and 8.2 (dual-axis code review) are complete within those explicit boundaries. Tasks 2.1 (cascade contract/all-field acceptance), 5.2 (macOS capture), 8.3 (Windows full manual workflow) and 8.4 (macOS build/manual workflow) remain open. Worktrees are retained while acceptance is incomplete.

Acceptance evidence and unexecuted cases: docs/desktop-shell/html-page-annotations-acceptance.md.

Trae User added 28 commits November 18, 2026 23:13
Execution request-context records use the user role with is_meta set. Reuse the existing real-user predicate after protocol deserialization, retain exact admission and identity assertions, and seed context coverage on every platform.
…otations

# Conflicts:
#	web/scripts/i18n-en-overrides.mjs
#	web/src/i18n/sourceCatalog.generated.js
#	web/src/lib/api.js
Trae User added 8 commits November 22, 2026 00:01
- openspec/changes/redesign-html-page-annotations: 新变更包(proposal/design/tasks/tickets/spec)
- docs/specs: PRD、需求基线、技术设计、WIP 定性、验证方案、旧分支映射
- docs/agents/issue-tracker.md: GitHub 工单配置
- 旧 change add-html-page-annotations 四份文档标注 Superseded
旧路线收尾打磨,未按新方案对齐。逐文件定性见
docs/specs/2026-11-22-html-page-annotations-wip-alignment.md(保留 19 / 改造 24 / 废弃 8)。
记录标识与文档解耦:现行 <document_id>:annotation:<n> 在刷新后结构性失效
(document_id 内含 epoch,替换时清空且 runtime 销毁),成功率 0/10 而非概率问题;
另发现 targets[].locator 只有 tag#id,撑不起重放定位。

捕获耗时实测(无头 Edge,页面侧裁剪):做了 scale=1/dpr 时最大档 P95 37ms,
不做则 DPR2 下 P95 238ms 越线 —— scale 修正是硬要求。因此保存走异步补图。

- 新增 2026-11-22-html-page-annotations-t0-findings.md
- 技术设计:D9(记录标识)、D10(异步补图)、§4.8 流程图、新增 §4.12
记录归属会话,页签只是渲染/编辑端点(Q33)。PageAnnotationSession 不再持有
records_/next_number_,改为转发 SessionAnnotationStore。

标识与文档解耦(#208/D9):<page_id>:annotation:<n>,document_id 降为记录属性。
编号按 page_id 分组连续,仍与旧实现等价;discard 只清本页签并归 1。

行为零变化:49 条既有批注测试全绿;新增 5 条 store 契约测试。
host 层按 owner.session_id 共享 store 留给 #211。
Move pending annotation records to the session store so they outlive their page tab, capture screenshots at save time, and send annotations through the normal composer submission path. Remove the batch/reconcile protocol, native send leases, and the old integration driver.

Add pending and read-only sent cards, both edit paths, poll retry with backoff, and Enter/Shift+Enter/Ctrl+Enter semantics in the popup. Refresh the annotation tests and OpenSpec task record.
CI layer-lint failed R12: agent_browser_host.cpp (2856/2832) and
agent_browser_host_mac.mm (3240/3157) grew past the non-increasing
baseline. Extract instead of raising limits:

- move the duplicated set_bounds validation into agent_browser_common
- move the macOS synthetic input JS builders and CG mouse mapping into
  agent_browser_macos_helpers
- add SessionAnnotationStoreRegistry so both hosts stop carrying the
  same per-session store map

Both files are back under their baseline (2824 and 3129). The acceptance
doc no longer points at the deleted integration driver and its retired
batch/lease section, which also failed the documentation-path check.
…otations

# Conflicts:
#	web/src/i18n/sourceCatalog.generated.js
@LIUXIN557
LIUXIN557 marked this pull request as ready for review November 24, 2026 08:07
@tmoonlight

Copy link
Copy Markdown
Owner

审核结论:暂不合入

基于 51f3e105 做了一轮完整审核。下面的问题里有几条会影响既有的内嵌浏览器和发版,所以先不合,列出来请逐条处理。

这次做了什么、没做什么

  • 本机 Windows 编译通过(Ninja Release:acecode-desktop、acecode_unit_tests、agent_browser_host_smoke),改动涉及的 17 个测试套件 452 个用例全部通过。
  • CI 五项是绿的,但 test.yml 只在 Linux 上编译,Windows 和 macOS 的原生代码没有任何 CI 编译。下面第 2、3、4 条都在绿灯之下,其中两处测试断言的正是有问题的行为。
  • 没有实际运行桌面版。标「已确认」的是逐行对照代码确认的;标「待确认」的是读代码推断,需要真机或二次核对。
  • master 在审核期间合入了 修复Linux下字体偏高导致输入框底部控件文字显示不全问题。 #221(改了 InputBar.jsx、globals.css、Sidebar.jsx、GitSessionPill.jsx)。试合并无冲突,但需要再合一次 master 并重跑 CI。

一、合入前必须解决

1. external/cpp-mcp 子模块指针被退回旧提交(已确认)

  • 提交 44c3fad4(wip)把指针从 62a8c88 改回 3cd98f1,PR 的文档和提交说明里都没提,应是误带。
  • 丢掉的是 fix(stdio): limit the server process to its own pipe handles,也就是「升级时报文件被占用」的修复。
  • 改法:把指针恢复到 62a8c88。

2. 旧设计的导航围栏还在,影响所有页面(已确认)

位置:src/apps/desktop/page_annotation_navigation.hpp:12-31、page_annotation_host_adapter.hpp:37-51, 55-77、agent_browser_host.cpp:1326, 2043

  • navigating_ 从 NavigationStarting 一直保持到 NavigationCompleted。这期间 reserve() 直接失败,start() 只放行同一导航 id、服务端重定向和证书重试。
  • 后果一:页面还在加载时,地址栏输入新地址、后退、前进、刷新都被拒绝;agent 在上一次导航还没加载完时再调 browser_navigate 也会失败。这与是否用过批注无关,是既有内嵌浏览器的回归。
  • 后果二:加载完成前由页面发起的新导航(点链接、内联脚本跳转)在 NavigationStarting 里被 put_Cancel(TRUE) 取消。这一条的实际表现取决于 WebView2 的事件顺序,待真机确认。
  • 后果三:只要该页签还有未发记录,每次导航都弹原生模态框(MessageBoxW / NSAlert),文案是写死的英文。agent 发起的导航也会弹,无人值守时工具调用会卡到超时。
  • 后果四:发送成功后的 remove 也被这个闸门拦下(page_annotation_session.hpp:177-180),已发批注会回到待发列表,下次全量发送时重复发出。tests/desktop/page_annotation_session_test.cpp:764-776 把这个拦截断言成了预期行为。
  • docs/specs/2026-11-22-html-page-annotations-spec.md:103 已经写明「导航确认弹窗:不拦截用户操作」,tasks.md 也全部打了勾,但这套 reserve / arm / start 没有删。
  • 改法:整套围栏删除,只保留文档替换时的记录降级;remove 不受任何闸门限制,对应测试反过来断言。

3. 保存批注时的截图链路走不通(已确认,未实跑)

  • 校验恒为假:page_annotation_host_adapter.hpp:128 调 capture_screenshot(page, {{"format","png"}}, pending, "true"),把字面量 "true" 当校验表达式。求值结果是布尔值,而 page_annotation_host_submission.hpp:82-90 要求结果是带 valid == true 的对象。于是 validated_measure 恒返回 annotation_target_or_document_changed,Windows 上每条批注都没有缩略图和整屏图。没有任何测试走到 action: "screenshot"。
  • 大小上限自相矛盾:page_annotation_session.hpp:112 对整条命令限 262144 字节,排在 :139-140 的缩略图 512 KiB、整屏图 4 MiB 之前。前端把两张图放在同一条 attach_screenshot 里,而且是 PNG(web/src/lib/annotationCapture.js:73, 82),真实网页基本都会超,整条被拒。
  • 几何对不上(待确认):Windows 的 capture_screenshot 恒走整页捕获(agent_browser_capture_cdp.cpp:68-74),前端按视口图处理后再按视口坐标裁剪,页面高于视口或已滚动时裁出来的位置不对。
  • 改法:批注截图走视口捕获;去掉 "true" 或换成真正返回 {valid} 的表达式;attach_screenshot 单独设上限或拆成两条命令;补一条覆盖截图动作的测试。

4. macOS 链接缺符号(已确认,读 CMake 得出,未在 mac 上编译)

  • agent_browser_host_mac.mm:2939 新引用了 agent_browser_common::valid_agent_browser_bounds,它定义在 agent_browser_host_common.cpp。
  • 这个文件只在 ACECODE_AGENT_BROWSER_HOST_SOURCE 里(cmake/acecode_source_paths.cmake:24)。acecode_layer_libraries.cmake:173 先把它从 acecode_desktop_support 里剔除,随后 acecode_desktop.cmake:77 在 APPLE 上把这个变量整体换成 mac 的三个 .mm,于是它在 macOS 上没有被编进任何目标。master 的 mac 文件不引用这个命名空间,所以之前没问题。
  • 改法:把 agent_browser_host_common.cpp 加进 ACECODE_AGENT_BROWSER_HOST_MAC_SOURCE。发版要出 mac 包,合入前请在 mac 上至少编一次。

5. 铅笔编辑路径(已确认)

  • 编辑态不清:editing_record_id_ / draft_description_ 只在文档重置(page_annotation_session.hpp:212)和编辑保存(:503)两处清空,cancel、exit、start 都不清。点铅笔打开一条 → 取消 → 新建另一条并保存,会走编辑分支覆盖原记录;原记录若已被删除,循环找不到目标,新批注被丢弃但返回成功。
  • 定位不唯一:locator 是「标签名 + 可选的 #id」(page_annotation_runtime.hpp:97),编辑时直接 document.querySelector(locator)(:458-462)。没有 id 的元素会选中页面上第一个同名标签,保存后记录的目标被换成那个元素。id 里有需要转义的字符时直接查不到。
  • 多出图钉:编辑保存时原生仍下发 next_number(page_annotation_session.hpp:391),页内运行时无条件新建一个图钉(page_annotation_runtime.hpp:489-503),旧图钉不删。之后图钉与记录数量对不上,生命周期校验可能持续失败(这一步的后果待确认)。
  • 改法:取消 / 退出 / 开始 / 失败分支统一清编辑态,找不到被编辑记录时返回错误;活文档里直接用运行时持有的元素引用;图钉由原生全量下发、页内整体替换。

6. 发送链路(已确认)

  • 删除后仍会发出:web/src/components/PageAnnotationPendingCard.jsx:26-34 点垃圾桶后只在卡片里隐藏,5 秒后才真正删除;ChatView.jsx:4176 的 submitWithAnnotations 取的是待发箱全量。5 秒内发送,被删的那条照样发给模型。撤销也只有一个槽,连删两条时第一条会重新出现。
  • 「40 秒自查」走不到:web/src/lib/api.js:251 的默认请求超时是 30 秒,annotationSubmission.js:111-134 的 Promise.race 在 30 秒先收到 reject 并直接抛出。daemon 已收下但响应慢时,界面报发送失败,用户重试就是两条相同的批注。现有测试注入了短超时,所以测不出来。
  • 改法:删除立即从待发箱摘掉(撤销时放回),或发送组装时排除待删 id;超时类错误先自查再判失败,重试复用同一个 client_message_id。

7. 批注内容进模型的方式(已确认,设计层面)

  • daemon 侧相对 master 没有任何批注代码。page_annotations 走既有的「非 selection 上下文」通用路径(src/apps/web/routes/routes_sessions.cpp:603-609),服务端不校验结构、条数和长度。
  • 模型看到的是 "[Browser context]\n" 加一段 JSON,用户写的描述和网页原文(targets[].text、title、url)混在一起,没有任何说明哪部分来自网页。
  • 压缩后丢失:src/engine/agent/compaction/compact.cpp:268-299 只保留正文和 file 部件。用户没打字的批注消息压缩后变成一句图片占位文字;带字的只剩那句话。
  • Codex 路径收不到:src/adapters/provider/codex_provider.cpp:63-67 只认正文和文件引用,纯批注消息整条被跳过。
  • 建议:服务端识别 page_annotations,像 selection 那样净化后展开进正文(原文留作显示文本),展开时把用户描述与网页原文分段并标明来源,同时加上数量与长度上限。

8. 文档与测试(已确认)

  • docs/daemon-api.md:1856-1927 新增的整段描述的是 annotation_batch_id、annotation_reconcile_only、annotation_batch_not_accepted,这些在 src/ 里已经不存在;真正的新契约(contexts 里的 page_annotations)没有写。docs/agent-browser.md:500, 528-529 同样还是旧说法。
  • annotationEdit.test.js、annotationFocus.test.js、pageAnnotationCount.test.js、pageAnnotationEditDialog.test.js 没有被 web/src/lib/runTests.js 引入,pnpm test 和 CI 都不执行(直接用 node 跑是能过的)。
  • web/package.json 新增的 test:annotations:browser 指向 pageAnnotationStyles.browser.test.js,它导入的 ./pageAnnotationIntegration.browser.testHelper.js 不在仓库里,脚本一启动就失败。
  • 服务端两个新测试只发 text + client_message_id,不带 contexts,新契约在服务端零覆盖。

二、建议一并清理

  • web/src/lib/pageAnnotationMessage.js:8-19, 71-91 的「正文内嵌 Page annotations 载荷」解析:master 上从未有过这种正文格式,没有需要兼容的存量消息。保留它的后果是任何以 \n\nPage annotations\n{json} 结尾的用户消息都会被渲染成批注卡片(Message.jsx:334),JSON 段对用户不可见。建议删掉,只认上下文部件。
  • web/src/components/ChatView.jsx:4166-4169 新增两处 useCallback(fn, [annotationBox]),违反仓库「ChatView 里不写依赖会变的 useCallback」的规定。架构测试只扫顶层赋值,所以没拦住。
  • 与批注无关的改动:
    • web/src/styles/globals.css:2191 把 .ace-settings-narrow-bar 的 min-height 从 52px 改成 44px(手机竖屏设置页顶栏),来自 44c3fad4,请确认是否有意。
    • src/engine/agent/worker/agent_task_queue.hpp:11 多了没用到的 #include <map>;src/apps/web/routes/routes_sessions.cpp:2238 只是加了 const。建议撤回,让 PR 不碰 engine 和 web 两层。
    • web/check-copy.mjs、docs/agents/issue-tracker.md 没有被任何地方引用。
  • docs/specs/ 下三个文件写了本机绝对路径(…technical-design.md、…t0-findings.md、…wip-alignment.md)。
  • tests/CMakeLists.txt:79-82 把三个产品源文件直接编进 acecode_unit_tests,与 acecode_layer_libraries.cmake 里「测试只消费产品库」的约定相悖,建议放回 acecode_desktop_support。
  • 新增样式里有几处 line-height: 1(例如 .ace-page-annotation-message-summary)。刚合入的 修复Linux下字体偏高导致输入框底部控件文字显示不全问题。 #221 修的正是这一类:Linux 中文字体的字框高于 1em,截断的文字底部会被裁。建议在 Linux 上看一眼。
三、读代码发现、尚未二次核对的问题(请作者确认)
  • 页签关闭后,待发卡片上的删除走原生 remove,而 annotation_dispatch 对已关闭页面一律返回不可用(page_annotation_host_adapter.hpp:113-120 里 !page 先判),前端不看返回值也不改本地待发箱,记录删不掉。
  • submitWithAnnotations 在等截图上传期间没有重入保护,回复中连按两次 Enter 可能把同一批批注入队两次;等待期间新输入的文字没有发出,却会在成功后被清掉。
  • 有待发批注时,斜杠命令(/compact、/model 等)和 fork 发送都会失败,而且失败发生在截图上传之后。
  • 回复中有待发批注且输入框为空时,停止按钮变成发送(inputBarState.js:36-39,有测试守着,应是有意设计,需要产品决定)。
  • 页内工具栏的发送和浮窗 Ctrl+Enter 绕过输入框的可提交判定,提问挂起或只读会话时仍能发出。
  • 保存后补图的 effect 依赖每次渲染都是新对象的 annotations(AgentBrowserPanel.jsx:112-137),任一次重渲染都会取消在途截图。
  • 样式基准值取的是当前计算值(page_annotation_style_runtime.hpp:102-111),同一元素第二次修改时差异会记成「上次预览值 → 新值」,丢掉源码里的原始值。
  • 批注快照(含整屏图和缩略图)挂在页面状态上,随每次状态事件和每 250 毫秒一次的轮询整份下发;轮询在退出批注模式后不停;SessionAnnotationStoreRegistry 没有删除入口。目前被第 3 条压着,那两处一修好量级就上去了。
  • innerText.slice(0, 512) 可能切在代理对中间;表单里有 name="id" 的控件时 target.id 是元素而不是字符串。
  • macOS:target=_blank 链接可能因二次 reserve 失败而不加载;page_annotation_poller.hpp 里 block 捕获了引用形参。
  • Windows 上 browser_screenshot(full_page: true) 改走新的整页捕获管线,多了前置条件和几种失败码,懒加载页面可能稳定失败;tasks.md 的 P3 写的是「删整页路径」,代码里仍在。

四、这次没有审到的部分

  • PageAnnotations.jsx 的交互细节(样式面板、间距锁定)。
  • page_annotation_style_runtime.hpp、page_annotation_text_runtime.hpp 后半、agent_browser_capture_layout.cpp。
  • agent_browser_host_mac.mm 的 474 行改动,只看了求值与截图入口。
  • agentBrowserSurfaceCoordinator.js 把所有浮层的原生挖洞取整规则改成向外取整再加 1 像素,对既有菜单和提示的遮挡边缘有没有影响,需要在 Windows 和 mac 上实机看。

核对过、没有问题的部分

  • 页面脚本碰不到批注运行时(Windows 是隔离 world,mac 是具名 content world),保存只能由主界面的 bridge 触发,交互事件都要求 isTrusted。
  • 新组件没有 dangerouslySetInnerHTML、innerHTML、href;缩略图只进 <img src>,原生限定 data:image/ 前缀。
  • 没有批注时,普通发送、Enter 插话、Ctrl+Enter 排队、fork、排队卡片、粘贴、附件、@ 引用各条路径与 master 等价。
  • Prompt cache 前缀不变量没有被破坏;整屏图走既有的附件与图片压缩路径。
  • 行数棘轮、size_baseline.txt、ownership_baseline.json、src/layers.tsv 都没有放宽;check_ownership.py 的改动只是修 #include <new> 的误报,并带了测试。
  • 896b19d9 的拆分是等价搬运(除了第 4 条的链接问题)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment